//
// Created by ins on 2021/3/6.
//

#include "BossPresenter.h"
#include "BossBean.h"
#include "json.h"
#include "BossDao.h"
BossDao *bossDao;
using namespace std;

void getBoss(string data, ResData& res_data);
moduleHandler boss_cmds[] = {
        {"01", getBoss}
};

void getBoss(string data, ResData& res_data){
    BossBean cxboss;

    Json::Value root = Util::init_root(data);
    if(!root["sid"].isNull()){
        string bossid = root["bossid"].asString();

        bossDao->getBoss(bossid, cxboss);

        if(cxboss.getId() == ""){
            res_data.resp_code = ERRCD_NOPLAYER;
        }else{
            res_data.resp_code = ERRCD_PASS;
            res_data.resp_data = "\"boss\":" + cxboss.toString();
        }
    }
}

BossPresenter::BossPresenter() {

}
BossPresenter::~BossPresenter(){}

void BossPresenter::BossMsgHandler(string cmd, string data, ResData &outData) {
    cout << "subCmd: " << cmd << endl;
    cout << "boss: " << data << endl;

    int i = 0;

    if(cmd.empty() || data.empty()){
        return;
    }

    for (i = 0; !boss_cmds[i].cmd.empty(); ++i)
    {
        if (cmd != boss_cmds[i].cmd)
            continue;
        break;
    }

    boss_cmds[i].func(data, outData);
}
